package com.gmq.chapter02.t2;

/**
 * Created by gmq on 2017/08/14.
 * 实例变量的变量为非线程安全
 *
 * @version 1.0
 * @since 2017/08/14 20:26
 */
public class HasSelfPrivateNum {

    private int num = 0;

    synchronized public void addI(String userName) {
        try {

            if ("a".equals(userName)) {
                num = 100;
                System.out.println("a set over");
                Thread.sleep(2000);
            } else {
                num = 200;
                System.out.println("b set over");
            }
            System.out.println(userName + " num = " + num);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

}
